package PlayCard;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    private static final String[] SUITS = {"♦", "♣", "♥", "♠"};

    public static List<Card> newCard() {
        List<Card> list = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                int rank = j;
                Card card = new Card(suit, rank);
                list.add(card);
            }
        }
        return list;
    }

    public static void washCard(List<Card> list) {
        Random random = new Random();
        for (int i = list.size() - 1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(list, i, index);
        }
    }

    //换牌
    private static void swap(List<Card> list, int i, int j) {
        Card tmp = list.get(i);
        list.set(i, list.get(j));
        list.set(j, tmp);
    }

    public static void main(String[] args) {
        List<Card> list = newCard();
        System.out.println(list);

        washCard(list);
        System.out.println(list);

        List<List<Card>> p = new ArrayList<>();

        List<Card> p1 = new ArrayList<>();
        List<Card> p2 = new ArrayList<>();
        List<Card> p3 = new ArrayList<>();

        p.add(p1);
        p.add(p2);
        p.add(p3);

        //发牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                p.get(j).add(card);
            }
        }

        System.out.println("A的牌：" + p.get(0));
        System.out.println("B的牌：" + p.get(1));
        System.out.println("C的牌：" + p.get(2));
        System.out.println("剩的牌：" + list);

    }
}
